<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div class="pagetop">
            <div v-if="hospdisable">
                <table>
                    <tr>
                        <td v-show="hospdisable" style="width: 50px">医院</td>
                        <td v-show="hospdisable">
                            <rm-ddl-common @change="hospitalChange" datatype="hospital" dataname="医院" v-model="hospitalval" width="240px"></rm-ddl-common>
                        </td>
                    </tr>
                </table>
            </div>
            <div style="position: absolute; right: 0px; top: 1px">
                <table style="">
                    <el-button icon="el-icon-search" @click="main_secsysrole_rfresh" v-has="'PQUERY'" type="primary">查询</el-button>
                    <el-button icon="el-icon-plus" @click="btn_addsecsysrole_clickEvent" v-has="'PADD'">新增</el-button>
                    <el-button icon="el-icon-edit" @click="btn_editsecsysrole_clickEvent" v-has="'PMODIFY'">修改</el-button>
                    <el-button icon="el-icon-delete" @click="btn_delsecsysrole_clickEvent" v-has="'PDELETE'">删除</el-button>
                </table>
            </div>
        </div>
        <div class="pagecenter">
            <!-- <div class="middle-center">
               
            </div>
            <div class="middle-right">
               
            </div> -->

            <rm-layout-right splitcolor="white" movingcolor="#00ffff" :splitwidth=5 fixsize="50%">
                <template v-slot:fix>
                    <div style="height:100%">
                        <el-tabs style="height: 100%" type="border-card" v-model="tab_showflag" @tab-click="tab_title_clickEvent">
                            <el-tab-pane label="角色用户" name="tabname_jsyh" :disabled="havedata">
                                <div>
                                    <table>
                                        <tr>
                                            <td style="width: 50px">用户大类</td>
                                            <td>
                                                <el-select v-model="sel_userkind" placeholder="请选择" style="width: 100px" @change="tab_get_jsyh_nohavendata" :disabled="havedata">
                                                    <el-option key="" label="所有" value=""></el-option>
                                                    <el-option key="1" label="检验用户" value="1"></el-option>
                                                    <el-option key="2" label="临床医生" value="2"></el-option>
                                                    <el-option key="3" label="临床护士" value="3"></el-option>
                                                    <el-option key="8" label="护工" value="8"></el-option>
                                                    <el-option key="9" label="其它用户" value="9"></el-option>
                                                </el-select>
                                            </td>
                                            <td>快速查询</td>
                                            <td>
                                                <el-input size="small" style="width: 150px" v-model="tab_jsyh_seachstr" @keyup.enter.native="tab_get_jsyh_nohavendata" placeholder="输入用户代号|名称|拼音码" :disabled="havedata"></el-input>
                                                <!-- <el-button icon="el-icon-search" @click="tab_get_jsyh_nohavendata" type="primary" :disabled="havedata">查询</el-button> -->
                                            </td>
                                            <td style="width: 80px;text-align:left">
                                                <el-popover placement="bottom" width="200" trigger="click" v-model="filtervisible">
                                                    <div>
                                                        <table>
                                                            <tr>
                                                                <td>医生级别</td>
                                                                <td>
                                                                    <el-select v-model="sel_doctorkind" placeholder="请选择" style="width: 120px" clearable @change="tab_get_jsyh_nohavendata">
                                                                        <el-option key="10" label="普通医生" value="10"></el-option>
                                                                        <el-option key="20" label="主治医生" value="20"></el-option>
                                                                        <el-option key="30" label="副主任医生" value="30"></el-option>
                                                                        <el-option key="40" label="主任医生" value="40"></el-option>
                                                                    </el-select>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>主任标志</td>
                                                                <td>
                                                                    <el-select v-model="sel_doctormaster" placeholder="请选择" style="width: 120px" clearable @change="tab_get_jsyh_nohavendata">
                                                                        <el-option key="0" label="非主任" value="0"></el-option>
                                                                        <el-option key="1" label="科副主任" value="1"></el-option>
                                                                        <el-option key="2" label="科主任" value="2"></el-option>
                                                                    </el-select>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </div>
                                                    <el-button slot="reference">高级查询</el-button>
                                                </el-popover>
                                            </td>
                                            <td style="font-size: 12px; color: blue">双击左边添加，双击右边删除</td>
                                            <td style="width: 10px">&nbsp;</td>
                                            <td style="text-align: right">
                                                <el-button icon="el-icon-sort" @click="tab_jsyh_exchangeEvent">交换选中</el-button>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="middle-tab-bottom">
                                    <div style="float: left; width: 100%; height: 26px">
                                        <div style="float: left; width: calc(50% - 3px); height: 100%; text-align: center; background: #f5f5f5; border: solid 1px #ccc; line-height: 26px; font-size: 13px">可添加用户</div>
                                        <div style="float: left; height: 100%; width: calc(50% - 3px); margin-left: 5px; text-align: center; background: #f5f5f5; border: solid 1px #ccc; line-height: 26px; font-size: 13px">本角色用户</div>
                                    </div>
                                    <div style="float: left; width: 100%; height: calc(100% - 26px); margin-top: -1px">
                                        <div style="float: left; width: calc(50% - 3px); height: 100%">
                                            <vxe-table :data.sync="tab_jsyh_nohavenuser_data" :loading="tab_jsyh_nohavenuser_loading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow header-align="center" ref="tab_jsyh_nohaven_table" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" @cell-dblclick="tab_jsyh_nohavenuser_dbclickEvent">
                                                <vxe-table-column type="selection" width="40" align="center"></vxe-table-column>
                                                <vxe-table-column field="userno" sortable title="代号" width="60" show-overflow></vxe-table-column>
                                                <vxe-table-column field="username" sortable title="名称" width="60" show-overflow></vxe-table-column>
                                                <vxe-table-column field="userkindname" sortable title="大类" width="70" show-overflow></vxe-table-column>
                                                <vxe-table-column field="doctorkindname" sortable title="医生分级" width="70" show-overflow></vxe-table-column>
                                                <vxe-table-column field="doctormastername" sortable title="主任标志" width="70" show-overflow></vxe-table-column>
                                                <vxe-table-column field="deptno" sortable title="所属科室" width="70" show-overflow></vxe-table-column>
                                                <vxe-table-column field="hospcode" sortable title="所属医院" width="100" show-overflow></vxe-table-column>
                                            </vxe-table>
                                        </div>
                                        <div style="float: left; height: 100%; width: calc(50% - 3px); margin-left: 5px">
                                            <vxe-table :data.sync="tab_jsyh_havenuser_data" :loading="tab_jsyh_havenuser_loading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow header-align="center" ref="tab_jsyh_haven_table" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" @cell-dblclick="tab_jsyh_havenuser_dbclickEvent">
                                                <vxe-table-column type="selection" width="40" align="center"></vxe-table-column>
                                                <vxe-table-column field="userno" sortable title="代号" width="60" show-overflow></vxe-table-column>
                                                <vxe-table-column field="username" sortable title="名称" width="60" show-overflow></vxe-table-column>
                                                <vxe-table-column field="userkindname" sortable title="大类" width="60" show-overflow></vxe-table-column>
                                                <vxe-table-column field="doctorkindname" sortable title="医生分级" width="70" show-overflow></vxe-table-column>
                                                <vxe-table-column field="doctormastername" sortable title="主任标志" width="70" show-overflow></vxe-table-column>
                                                <vxe-table-column field="deptno" sortable title="所属科室" width="70" show-overflow></vxe-table-column>
                                                <vxe-table-column field="hospcode" sortable title="所属医院" width="100" show-overflow></vxe-table-column>
                                                <vxe-table-column field="rolevaliditydt" sortable title="有效期至" width="120" show-overflow></vxe-table-column>
                                            </vxe-table>
                                        </div>
                                    </div>
                                </div>
                            </el-tab-pane>
                            <el-tab-pane label="菜单授权" name="tabname_cdsq" :disabled="havedata">
                                <div class="middle-tab-top">
                                    <table style="width: 100%">
                                        <tr>
                                            <td style="text-align: left">
                                                <el-input size="small" style="width: 150px" v-model="tab_cdsq_seachstr" placeholder="关键字过滤"></el-input>&nbsp;&nbsp;
                                                <el-button icon="el-icon-document" @click="tab_cdsq_saveTreeEvent" :disabled="havedata">保存</el-button>
                                                <el-button icon="el-icon-document-copy" @click.native="menuauthevent('copy')" :disabled="havedata">复制</el-button>
                                                <el-button icon="el-icon-document-add" @click.native="menuauthevent('paste')" :disabled="havedata">粘贴</el-button>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="middle-tab-bottom">
                                    <el-tree class="filter-tree" :data="tab_cdsq_data" show-checkbox node-key="id" :default-checked-keys="tab_cdsq_tree_havendata" ref="tab_cdsq_tree" :filter-node-method="filterNode"> </el-tree>
                                </div>
                            </el-tab-pane>
                            <el-tab-pane label="LIS授权" name="tabname_lissq" :disabled="havedata">
                                <div class="middle-tab-top">
                                    <table style="width: 100%">
                                        <tr>
                                            <td>
                                                <el-radio-group v-model="tab_lis_pobject" @change="lisproject_changeEvent">
                                                    <el-radio label="LG" :disabled="!is2101">检验组</el-radio>
                                                    <el-radio label="RU" :disabled="is2101">报告单元</el-radio>
                                                    <el-radio label="IS" :disabled="is2101">仪器</el-radio>
                                                </el-radio-group>
                                            </td>
                                            <td>
                                                <el-checkbox v-model="tab_lis_ismemory" style="margin-left: 50px">自动记忆</el-checkbox>
                                                <el-checkbox @change="tab_lis_selectChanegCEvent" style="margin-left: 50px">全选/取消</el-checkbox>
                                            </td>
                                            <td style="text-align: right">
                                                <el-button icon="el-icon-document" @click="tab_lis_saveBtnEvent" :disabled="havedata">保存</el-button>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="middle-tab-bottom">
                                    <div style="float: left; width: 200px; height: 100%">
                                        <div style="width: 200px; height: calc(50% - 2px)">
                                            <div style="float: left; width: 100%; height: 26px">
                                                <div style="width: 100%; height: 100%; text-align: center; background: #f5f5f5; border: solid 1px #ccc; line-height: 26px; font-size: 13px">
                                                    <font color="#409EFF">已授权对象</font>
                                                </div>
                                            </div>
                                            <div style="float: left; width: 100%; height: calc(100% - 26px); margin-top: -1px">
                                                <vxe-table :data.sync="tab_lis_havendata" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="lisYtable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" @cell-dblclick="tab_lis_dbclickDelEvent" @current-change="lisYtable_changeEvent">
                                                    <vxe-table-column field="name" sortable title="对象名称" width="280" show-overflow></vxe-table-column>
                                                </vxe-table>
                                            </div>
                                        </div>
                                        <div style="width: 200px; height: calc(50% - 3px); margin-top: 5px">
                                            <div style="float: left; width: 100%; height: 26px">
                                                <div style="width: 100%; height: 100%; text-align: center; background: #f5f5f5; border: solid 1px #ccc; line-height: 26px; font-size: 13px">
                                                    <font color="#F56C6C">未授权对象</font>
                                                </div>
                                            </div>
                                            <div style="float: left; width: 100%; height: calc(100% - 26px); margin-top: -1px">
                                                <vxe-table :data.sync="tab_lis_nohavendata" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="lisNtable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" @cell-dblclick="tab_lis_dbclickAddEvent">
                                                    <vxe-table-column field="name" sortable title="对象名称" width="280" show-overflow></vxe-table-column>
                                                </vxe-table>
                                            </div>
                                        </div>
                                    </div>
                                    <div style="float: left; height: 100%; width: calc(100% - 205px); margin-left: 5px">
                                        <vxe-table :data.sync="tab_lis_pdictdata" :loading="tab_lis_pdictdata_loading" :select-config="{ reserve: true, showHeader: false, trigger: 'row', tab_lis_checkMethod }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column how-header-overflow ref="lisDicttable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" :span-method="lis_rowspanmethod" @select-change="tab_lis_dictTablechangeEvent" :row-class-name="LisDictRowClassName">
                                            <vxe-table-column field="powerobjectname" title="应用对象" width="80" show-overflow></vxe-table-column>
                                            <vxe-table-column field="powerclassname" title="权限分类" width="90" show-overflow></vxe-table-column>
                                            <vxe-table-column type="selection" width="38" :disabled="true"></vxe-table-column>
                                            <vxe-table-column field="powername" title="权限名称" width="150" show-overflow></vxe-table-column>
                                            <vxe-table-column field="description" title="备注说明" width="400" show-overflow></vxe-table-column>
                                        </vxe-table>
                                    </div>
                                </div>
                            </el-tab-pane>
                            <el-tab-pane label="报告项目按类别授权" name="tabname_bgxmalbsq" :disabled="havedata" v-if="lab_rptitemauth">
                                <div class="middle-tab-top">
                                    <table style="width: 100%">
                                        <tr>
                                            <td style="width: 80px">&nbsp;</td>
                                            <td style="font=size: 17px; color: blue">可双击左边添加，双击右边删除(如果双击父节点，则父节点下所有子节点都会新增或删除)</td>
                                            <td style="width: 80px">&nbsp;</td>
                                            <!-- <td>快速查询</td>
                                    <td>
                                        <el-input size="small" style="width: 150px" v-model="tab_bgxmalb_seachstr" @keyup.enter.native="tab_get_bgxmalb_nohavendata" placeholder="输入项目类别"></el-input>
                                    </td> -->
                                        </tr>
                                    </table>
                                </div>
                                <div class="middle-tab-bottom">
                                    <div style="float: left; width: 100%; height: 26px">
                                        <div style="float: left; width: calc(50% - 3px); height: 100%; text-align: center; background: #f5f5f5; border: solid 1px #ccc; line-height: 26px; font-size: 13px">未授权项目类别</div>
                                        <div style="float: left; height: 100%; width: calc(50% - 3px); margin-left: 5px; text-align: center; background: #f5f5f5; border: solid 1px #ccc; line-height: 26px; font-size: 13px">已授权项目类别</div>
                                    </div>
                                    <div style="float: left; width: 100%; height: calc(100% - 26px); margin-top: -1px">
                                        <div style="float: left; width: calc(50% - 3px); height: 100%">
                                            <vxe-table :data.sync="tab_bgxmalb_nohavendata" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow :loading="tab_bgxmalb_nohaveloading" ref="bgxmalbNtable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" @cell-dblclick="tab_bgxmalb_dbclickAddEvent">
                                                <vxe-table-column field="itemclassname" sortable title="项目类别名称" width="180" show-overflow>
                                                    <template v-slot="{row}">
                                                        <div style="text-indent:2em;font-weight:800" v-if="row.classlevel == '1'">{{row.itemclassname}}</div>
                                                        <div style="text-indent:4em;font-weight:400" v-else-if="row.classlevel == '2'">{{row.itemclassname}}</div>
                                                        <div v-else-if="row.classlevel == '3'" style="text-indent:6em;">{{row.itemclassname}}</div>
                                                        <div v-else style="font-weight:bolder">{{row.itemclassname}}</div>
                                                    </template>
                                                </vxe-table-column>
                                                <vxe-table-column field="itemclasscode" sortable title="项目类别代码" width="100" show-overflow header-align="center"></vxe-table-column>
                                                <vxe-table-column field="itemclassid" sortable title="项目类别ID" width="100" show-overflow header-align="center"></vxe-table-column>
                                            </vxe-table>
                                        </div>
                                        <div style="float: left; height: 100%; width: calc(50% - 3px); margin-left: 5px">
                                            <vxe-table :data.sync="tab_bgxmalb_havendata" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border :loading="tab_bgxmalb_haveloading" height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="bgxmalbYtable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" @cell-dblclick="tab_bgxmalb_dbclickDelEvent">
                                                <vxe-table-column field="itemclassname" sortable title="项目类别名称" width="180" show-overflow>
                                                    <template v-slot="{row}">
                                                        <div style="text-indent:2em;font-weight:800" v-if="row.classlevel == '1'">{{row.itemclassname}}</div>
                                                        <div style="text-indent:4em;font-weight:400" v-else-if="row.classlevel == '2'">{{row.itemclassname}}</div>
                                                        <div v-else-if="row.classlevel == '3'" style="text-indent:6em;">{{row.itemclassname}}</div>
                                                        <div v-else style="font-weight:bolder">{{row.itemclassname}}</div>
                                                    </template>
                                                </vxe-table-column>
                                                <vxe-table-column field="itemclasscode" sortable title="项目类别代码" width="100" show-overflow header-align="center"></vxe-table-column>
                                                <vxe-table-column field="itemclassid" sortable title="项目类别ID" width="100" show-overflow header-align="center"></vxe-table-column>
                                            </vxe-table>
                                        </div>
                                    </div>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </div>
                </template>
                <div style="height:100%;width:100%;">
                    <vxe-table :data.sync="main_secsysrole_data" :loading="main_secsysrole_loading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="main_secsysrole_table" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" @current-change="main_secsysrole_table_curchangeEvent" header-align="center">
                        <vxe-table-column field="roleno" sortable title="代码" width="60" show-overflow></vxe-table-column>
                        <vxe-table-column field="rolename" sortable title="名称" width="90" show-overflow></vxe-table-column>
                        <vxe-table-column field="isdefault" sortable title="内置" width="40" show-overflow align="center">
                            <template v-slot="{ row, rowIndex, columnIndex }">
                                <div :key="row.roleno + rowIndex + columnIndex" v-if="row.isdefault == '1'">
                                    <el-checkbox checked disabled></el-checkbox>
                                </div>
                                <div :key="row.userno + rowIndex + columnIndex" v-else>
                                    <el-checkbox disabled></el-checkbox>
                                </div>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="isneedexm" sortable title="可通过考试授予" width="75" show-overflow align="center">
                            <template v-slot="{ row, rowIndex, columnIndex }">
                                <div :key="row.isneedexm + rowIndex + columnIndex" v-if="row.isneedexm == '1'">
                                    <el-checkbox checked disabled></el-checkbox>
                                </div>
                                <div :key="row.userno + rowIndex + columnIndex" v-else>
                                    <el-checkbox disabled></el-checkbox>
                                </div>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="hospname" sortable title="所属医院" width="200">
                            <!-- <template v-slot="{ row }">
                            <rm-ddl-common datatype="hospital" dataname="医院" v-model="row.hospcode" width="180px" :disabled="true"></rm-ddl-common>
                        </template> -->
                        </vxe-table-column>
                        <vxe-table-column field="adminusername" sortable title="主管" width="70" show-overflow></vxe-table-column>
                    </vxe-table>
                </div>
            </rm-layout-right>
        </div>
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="main_secsysrole_dialog_name" :visible.sync="main_secsysrole_dialogflag" @close="main_secsysrole_dialogcloseEvent" width="500px">
            <div>
                <table>
                    <tr>
                        <td>
                            <font color="#F56C6C">角色代码</font>
                        </td>
                        <td colspan="2">
                            <el-input style="width: 280px" v-model="main_secsysrole_dialog_info.roleno" :disabled="main_secsysrole_dialog_display" @change="rolenochange_event"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <font color="#F56C6C">角色名称</font>
                        </td>
                        <td colspan="2">
                            <el-input style="width: 280px" v-model="main_secsysrole_dialog_info.rolename" :disabled="rolenameflag"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>主管</td>
                        <td colspan="2">
                            <rm-ddl-common datatype="userinfo" dataname="用户" v-model="main_secsysrole_dialog_info.adminuserno" width="280px"></rm-ddl-common>
                        </td>
                    </tr>
                    <tr>
                        <td>{{ lblhosp }}</td>
                        <td>
                            <div v-if="!hospdisable">
                                <!-- <rm-ddl-common datatype="hospital" dataname="医院" v-model="main_secsysrole_dialog_info.hospcode" width="180px" :disabled="!hospdisable"></rm-ddl-common> -->
                            </div>
                            <div v-else  class="dialogselect">
                                <el-select v-model="main_secsysrole_dialog_info.hospcode">
                                    <el-option v-for="(item, index) in hospoption" :key="index" :label="item.label" :value="item.value"></el-option>
                                </el-select>
                            </div>
                        </td>
                        <td>
                            <el-checkbox v-model="main_secsysrole_dialog_info.isdefault" :disabled="isdefaultflag">是否系统内置</el-checkbox>
                            <el-checkbox v-model="main_secsysrole_dialog_info.isneedexm"  >是否可通过考试授予</el-checkbox>
                        </td>
                    </tr>
                </table>
            </div>
            <div style="margin-top: 5px; text-align: right">
                <el-button icon="el-icon-document" @click="btn_secsysrole_dialog_saveEvent">保存</el-button>
                <el-button icon="el-icon-close" @click="btn_secsysrole_dialog_cancelEvent">取消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script type="text/javascript">
import { Promise } from "q";
import XE from "xe-utils"; //引入工具类
import { invalid } from "moment";
export default {
    name: "MNG111",
    data() {
        return {
            tab_showflag: "tabname_jsyh",
            filtervisible: false,
            main_secsysrole_data: [],
            main_secsysrole_loading: false,
            main_secsysrole_info: {
                roleno: "",
                rolename: "",
                adminuserno: "",
                isdefault: false,
                hospcode: "All",
            },
            main_secsysrole_dialog_info: {
                roleno: "",
                rolename: "",
                adminuserno: "",
                isdefault: false,
                isneedexm:false,
                hospcode: "All",
            },
            main_secsysrole_dialogflag: false,
            tab_jsyh_nohavenuser_data: [],
            tab_jsyh_nohavenuser_loading: false,
            tab_jsyh_havenuser_data: [],
            tab_jsyh_havenuser_loading: false,
            tab_jsyh_seachstr: "",
            sel_doctorkind: "", //医生级别
            sel_doctormaster: "", //主任标志
            tab_cdsq_data: [],
            tab_cdsq_tree_havendata: [],
            tab_cdsq_seachstr: "",
            main_secsysrole_dialog_display: false,
            main_secsysrole_dialog_name: "",
            is2101: true,
            tab_lis_pobject: "LG",
            tab_lis_pdictdata: [],
            tab_lis_pdictdata_loading: false,
            tab_lis_pdictdata_old: [],
            tab_lis_havendata: [],
            tab_lis_nohavendata: [],
            tab_lis_savedata: [], //很重要！保存数据统一管理
            tab_lis_ismemory: true,
            isdefaultflag: false,
            rolenameflag: false,
            isarea: false,
            //roleOptions: [],
            copydata: [],
            menuauth: {},
            lblhosp: "",
            hospdisable: false,
            hospitalval: this.$tool.getSession(this.$tool.selectedhis),
            hospoption: [],
            sel_userkind: "",
            lab_rptitemauth: false,
            tab_bgxmalb_havendata: [],
            tab_bgxmalb_nohavendata: [],
            tab_bgxmalb_nohaveloading: false,
            tab_bgxmalb_haveloading: false,
        };
    },
    created() {
        this.main_secsysrole_rfresh();
        this.get_secoption();

        //add非区域LIS模式下所属医院固定为all不可编辑
        this.$ddldata.IsAreaModeFun().then((r) => {
            // if (this.$tool.getSession(this.$tool.loginutype) != "G") {
            //     //普通用户
            //     this.hospdisable = true;
            // } else {
            //     this.hospdisable = false;
            // }
            this.hospdisable = r;
            if (r) {
                this.lblhosp = "所属医院";
            }
            // console.info("3333=======" + r);
        });
    },
    watch: {
        tab_cdsq_seachstr(val) {
            this.$refs.tab_cdsq_tree.filter(val.toUpperCase());
        },
    },
    computed: {
        havedata() {
            if (this.main_secsysrole_data.length > 0) {
                return false;
            } else {
                return true;
            }
        },
    },
    mounted() {},
    updated() {},
    methods: {
        get_secoption() {
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "get_secoption",
                    },
                })
                .then((res) => {
                    if (res.listRtn[0] == "1") {
                        this.is2101 = false;
                        this.tab_lis_pobject = "RU";
                    } else {
                        this.is2101 = true;
                        this.tab_lis_pobject = "LG";
                    }
                    this.isarea = res.isarea == "1" ? true : false;
                    this.hospoption = res.hospdata;
                    this.lab_rptitemauth = res.lab_rptitemauth == "1";
                    //this.is2101 = res[0] == "1" ? true : false;
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        hospitalChange(code, name) {
            this.hospitalval = code;
            this.main_secsysrole_rfresh();
        },
        main_secsysrole_rfresh() {
            this.get_secsysroledata("");
        },
        get_secsysroledata(roleno) {
            this.main_secsysrole_loading = true;
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysrole_rfresh",
                        hospcode: this.hospitalval,
                    },
                })
                .then((res) => {
                    this.main_secsysrole_data = XE.clone(res.Data, true);
                    let rowindex = 0;
                    if (res.Data.length > 0) {
                        if (roleno == "") {
                            this.$nextTick(() => {
                                this.$refs.main_secsysrole_table.setCurrentRow(this.main_secsysrole_data[rowindex]);
                            })
                        } else {
                            XE.each(this.main_secsysrole_data, (item, key) => {
                                if (item.roleno == roleno) {
                                    rowindex = key;
                                }
                            });
                            this.$refs.main_secsysrole_table.setCurrentRow(this.main_secsysrole_data[rowindex]);
                            let that = this;
                            XE.delay(
                                function (name) {
                                    that.$refs.main_secsysrole_table.scrollToRow(that.main_secsysrole_data[rowindex]);
                                },
                                200,
                                "settimeout200"
                            );
                        }
                        this.get_tabdata(this.main_secsysrole_data[rowindex]);
                    } else {
                        this.main_secsysrole_info.roleno = "";
                        //菜单授权
                        this.tab_cdsq_data = [];
                        this.tab_cdsq_tree_havendata = [];
                        //LIS授权
                        this.tab_lis_havendata = [];
                        this.tab_lis_nohavendata = [];
                        this.tab_lis_pdictdata_old = [];
                        //角色授权
                        this.tab_jsyh_havenuser_data = [];
                        this.tab_jsyh_nohavenuser_data = [];
                        this.tab_lis_pdictdata = [];
                    }

                    this.main_secsysrole_loading = false;

                   
                    // this.roleOptions = [];
                    // let hosplist = [];
                    // res.Data.forEach((item) => {
                    //     if (hosplist.findIndex((m) => m.code == item.hospcode) == -1) {
                    //         hosplist.push({ name: item.hospname, code: item.hospcode });
                    //     }
                    // });
                    // hosplist.forEach((item) => {
                    //     console.log(item);
                    //     let data = res.Data.filter((m) => m.hospcode == item.code);
                    //     if (data.length > 0) {
                    //         let option = [];
                    //         data.forEach((list) => {
                    //             option.push({ value: list.roleno, label: list.rolename });
                    //         });
                    //         this.roleOptions.push({ label: item.name, options: option });
                    //     }
                    // });
                    // if (res.Data.length > 0) this.menuauth.rolenname = res.Data[0].rolename + "[" + res.Data[0].roleno;
                })
                .catch((e) => {
                    this.$alert(e, "提示");
                    this.main_secsysrole_loading = false;
                });
        },
        main_secsysrole_table_curchangeEvent({ row, rowIndex, column, columnIndex }, event) {
            this.get_tabdata(row);
        },
        tab_title_clickEvent(tab, event) {
            console;
            if (tab.label == "角色用户") {
                this.tab_get_jsyh_nohavendata();
                this.tab_get_jsyh_havendata();
                this.tab_cdsq_seachstr = "";
            } else if (tab.label == "菜单授权") {
                this.tab_cdsq_getdata();
            } else if (tab.label == "LIS授权") {
                this.$nextTick(() => {
                    this.tab_lis_getalldata();
                });
            } else if (tab.label == "报告项目按类别授权") {
                this.tab_bgxmalb_nohavedata();
                this.tab_bgxmalb_havedata();
            }
        },
        get_tabdata(row) {
            this.main_secsysrole_info.roleno = row.roleno;
            this.main_secsysrole_info.rolename = row.rolename;
            this.main_secsysrole_info.adminuserno = row.adminuserno;
            this.main_secsysrole_info.isdefault = row.isdefault == "1" ? true : false;
            this.main_secsysrole_info.isneedexm = row.isneedexm == "1" ? true : false;
            this.main_secsysrole_info.hospcode = row.hospcode;
            if (this.tab_showflag == "tabname_jsyh") {
                this.tab_get_jsyh_nohavendata();
                this.tab_get_jsyh_havendata();
                this.tab_cdsq_seachstr = "";
            } else if (this.tab_showflag == "tabname_cdsq") {
                this.tab_cdsq_getdata();
            } else if (this.tab_showflag == "tabname_lissq") {
                this.tab_lis_getalldata();
            } else if (this.tab_showflag == "tabname_bgxmalbsq") {
                this.tab_bgxmalb_nohavedata();
                this.tab_bgxmalb_havedata();
            }
        },
        init_main_secsysrole_dialog_info() {
            this.main_secsysrole_dialog_info.roleno = "";
            this.main_secsysrole_dialog_info.rolename = "";
            this.main_secsysrole_dialog_info.adminuserno = "";
            this.main_secsysrole_dialog_info.isdefault = false;
            this.main_secsysrole_dialog_info.isneedexm = false;
            this.main_secsysrole_dialog_info.hospcode = this.hospitalval;
        },
        main_secsysrole_dialogcloseEvent() {
            this.init_main_secsysrole_dialog_info();
            this.main_secsysrole_dialog_display = false;
        },
        btn_addsecsysrole_clickEvent() {
            this.init_main_secsysrole_dialog_info();
            this.main_secsysrole_dialog_display = false;
            this.main_secsysrole_dialog_name = "添加";
            this.main_secsysrole_dialogflag = true;
            this.isdefaultflag = false;
            //this.isneedexmflag = false;
            this.rolenameflag = false;
        },
        btn_editsecsysrole_clickEvent() {
            if (this.main_secsysrole_info.roleno == "") {
                this.$message.error("请选择需要编辑的数据！");
                return false;
            }
            this.main_secsysrole_dialog_info = XE.clone(this.main_secsysrole_info, true);
            this.main_secsysrole_dialog_name = "编辑";
            this.main_secsysrole_dialog_display = true;
            this.isdefaultflag = true;
            if (this.main_secsysrole_dialog_info.isdefault) {
                this.rolenameflag = true;
            } else {
                this.rolenameflag = false;
            }
            this.main_secsysrole_dialogflag = true;
        },
        btn_delsecsysrole_clickEvent() {
            if (this.main_secsysrole_info.roleno == "") {
                this.$message.error("请选择需要删除的数据！");
                return false;
            }
            if (this.main_secsysrole_info.isdefault) {
                this.$message.error("系统内置不可删除！");
                return false;
            }
            let _this = this;
            this.$confirm("此操作将永久删除该角色, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.$tool
                        .request({
                            url: "MNG/MNG1/MNG111",
                            method: "post",
                            data: {
                                action: "secsysrole_addoredit_del",
                                roleno: this.main_secsysrole_info.roleno,
                            },
                        })
                        .then((res) => {
                            if (res.errcode == "1") {
                                _this.$pub.message(_this, "删除成功！", "success");
                                //刷新
                                _this.get_secsysroledata("");
                            } else {
                                _this.$message.error(res.errmsg);
                            }
                        })
                        .catch((e) => {
                            this.$message.error(e);
                        });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },
        //新增保存
        btn_secsysrole_dialog_saveEvent() {
            if (this.main_secsysrole_dialog_info.roleno == "") {
                this.$message({
                    message: "角色代码不可为空！",
                    type: "warning",
                });
                return false;
            }
            if (this.main_secsysrole_dialog_info.rolename == "") {
                this.$message({
                    message: "角色名称不可为空！",
                    type: "warning",
                });
                return false;
            }
            if (this.main_secsysrole_dialog_info.hospcode == "") {
                this.$message({
                    message: "医院不可为空！",
                    type: "warning",
                });
                return false;
            }
            let _this = this;
            let datainfo = XE.clone(this.main_secsysrole_dialog_info, true);
            datainfo.isdefault = this.main_secsysrole_dialog_info.isdefault ? "1" : "0";
            datainfo.isneedexm = this.main_secsysrole_dialog_info.isneedexm ? "1" : "0";
            let datajson = JSON.stringify(datainfo);
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysrole_addoredit_save",
                        data: datajson,
                        addoredit: _this.main_secsysrole_dialog_name,
                    },
                })
                .then((res) => {
                    if (res.errcode == "1") {
                        _this.$pub.message(this, "保存成功！", "success");
                        //保存后清空缓存数据
                        _this.init_main_secsysrole_dialog_info();
                        _this.main_secsysrole_dialog_display = false;
                        _this.main_secsysrole_info = XE.clone(this.main_secsysrole_dialog_info, true);
                        _this.main_secsysrole_dialogflag = false;
                        //刷新
                        _this.get_secsysroledata(datainfo.roleno);
                    } else {
                        _this.$alert(res.errmsg, "出错");
                    }
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        btn_secsysrole_dialog_cancelEvent() {
            this.main_secsysrole_dialogflag = false;
        },
        rolenochange_event() {
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "roleno_validation",
                        roleno: _this.main_secsysrole_dialog_info.roleno,
                    },
                })
                .then((res) => {
                    if (res != "1") {
                        _this.$message.error("角色代号不可重复！");
                        _this.main_secsysrole_dialog_info.roleno = "";
                    }
                })
                .catch((e) => {
                    _this.$message.error(e);
                });
        },
        //报告项目按类别授权
        tab_bgxmalb_nohavedata() {
            this.tab_bgxmalb_nohaveloading = true;
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysreqitemclass_nohaven_query",
                        roleno: _this.main_secsysrole_info.roleno,
                        hospcode: _this.main_secsysrole_info.hospcode,
                        seachstr: _this.tab_jsyh_seachstr,
                        userkind: _this.sel_userkind,
                    },
                })
                .then((res) => {
                    this.tab_bgxmalb_nohavendata = res.data;
                    this.tab_bgxmalb_nohaveloading = false;
                })
                .catch((e) => {
                    this.$alert(e, "提示");
                });
        },
        tab_bgxmalb_havedata() {
            this.tab_bgxmalb_haveloading = true;
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysreqitemclass_haven_query",
                        roleno: _this.main_secsysrole_info.roleno,
                        hospcode: _this.main_secsysrole_info.hospcode,
                    },
                })
                .then((res) => {
                    this.tab_bgxmalb_havendata = res.data;
                    this.tab_bgxmalb_haveloading = false;
                })
                .catch((e) => {
                    this.$alert(e, "提示");
                });
        },
        //角色授权
        tab_get_jsyh_nohavendata() {
            this.tab_jsyh_nohavenuser_loading = true;
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysuser_nohaven_query",
                        roleno: _this.main_secsysrole_info.roleno,
                        hospcode: _this.main_secsysrole_info.hospcode,
                        seachstr: _this.tab_jsyh_seachstr,
                        userkind: _this.sel_userkind,
                        doctorkind: _this.sel_doctorkind,
                        doctormaster: _this.sel_doctormaster,
                    },
                })
                .then((res) => {
                    this.tab_jsyh_nohavenuser_data = res.Data;
                    this.tab_jsyh_nohavenuser_loading = false;
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        tab_get_jsyh_havendata() {
            this.tab_jsyh_havenuser_loading = true;
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysuser_haven_query",
                        roleno: _this.main_secsysrole_info.roleno,
                        hospcode: _this.main_secsysrole_info.hospcode,
                    },
                })
                .then((res) => {
                    this.tab_jsyh_havenuser_data = res.Data;
                    this.tab_jsyh_havenuser_loading = false;
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        tab_jsyh_exchangeEvent() {
            if (this.isarea && this.main_secsysrole_info.hospcode == "All" && this.$tool.getSession(this.$tool.loginutype) != "G" && this.$tool.getSession(this.$tool.loginutype) != "R") {
                this.$message({
                    type: "warning",
                    message: "医院代码All不可修改！",
                });
                return false;
            }
            if (this.main_secsysrole_info.roleno == "") {
                this.$message.error("请选择角色数据！");
                return false;
            }
            let nohaven_removeRecords = this.$refs.tab_jsyh_nohaven_table.getSelectRecords();
            let haven_removeRecords = this.$refs.tab_jsyh_haven_table.getSelectRecords();
            if (nohaven_removeRecords.length <= 0 && haven_removeRecords.length <= 0) {
                this.$message.error("请先选择交换数据！");
                return false;
            }
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysuser_exchange_save",
                        roleno: _this.main_secsysrole_info.roleno,
                        nohaven_removeRecords: nohaven_removeRecords,
                        haven_removeRecords: haven_removeRecords,
                    },
                })
                .then((res) => {
                    if (res.errcode == "1") {
                        _this.$pub.message(this, "保存成功！", "success");
                        _this.tab_get_jsyh_nohavendata();
                        _this.tab_get_jsyh_havendata();
                    } else {
                        _this.$message.error(res.errmsg);
                    }
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        tab_jsyh_nohavenuser_dbclickEvent({ row, rowIndex, column, columnIndex }, event) {
            if (this.isarea && this.main_secsysrole_info.hospcode == "All" && this.$tool.getSession(this.$tool.loginutype) != "G" && this.$tool.getSession(this.$tool.loginutype) != "R") {
                this.$message({
                    type: "warning",
                    message: "医院代码All不可修改！",
                });
                return false;
            }
            if (this.main_secsysrole_info.roleno == "") {
                this.$message.error("请选择角色数据！");
                return false;
            }
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysuser_dbclick_add",
                        roleno: _this.main_secsysrole_info.roleno,
                        userno: row.userno,
                    },
                })
                .then((res) => {
                    if (res.errcode == "1") {
                        _this.$pub.message(_this, "添加成功！", "success");
                        _this.tab_get_jsyh_nohavendata();
                        _this.tab_get_jsyh_havendata();
                    } else {
                        _this.$message.error(res.errmsg);
                    }
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        tab_jsyh_havenuser_dbclickEvent({ row, rowIndex, column, columnIndex }, event) {
            if (this.isarea && this.main_secsysrole_info.hospcode == "All" && this.$tool.getSession(this.$tool.loginutype) != "G" && this.$tool.getSession(this.$tool.loginutype) != "R") {
                this.$message({
                    type: "warning",
                    message: "医院代码All不可修改！",
                });
                return false;
            }
            if (this.main_secsysrole_info.roleno == "") {
                this.$message.error("请选择角色数据！");
                return false;
            }
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysuser_dbclick_del",
                        roleno: _this.main_secsysrole_info.roleno,
                        userno: row.userno,
                    },
                })
                .then((res) => {
                    if (res.errcode == "1") {
                        _this.$message({
                            message: "删除成功！",
                            type: "success",
                        });
                        _this.tab_get_jsyh_nohavendata();
                        _this.tab_get_jsyh_havendata();
                    } else {
                        _this.$message.error(res.errmsg);
                    }
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },

        lisproject_changeEvent() {
            this.tab_lis_getalldata();
        },
        tab_lis_dbclickDelEvent({ row, rowIndex, column, columnIndex }, event) {
            if (this.isarea && this.main_secsysrole_info.hospcode == "All" && this.$tool.getSession(this.$tool.loginutype) != "G" && this.$tool.getSession(this.$tool.loginutype) != "R") {
                this.$message({
                    type: "warning",
                    message: "医院代码All不可修改！",
                });
                return false;
            }
            //处理提交数据
            //找有没有添加记录  如果有：直接删除该添加记录  如果没有：新增一条删除记录
            let selectRecords = this.$refs.lisDicttable.getSelectRecords();
            XE.each(selectRecords, (s_item, s_key) => {
                let isAdd = false;
                XE.each(this.tab_lis_savedata, (item, key) => {
                    if (item.groupno == this.main_secsysrole_info.roleno && item.powerobject == this.tab_lis_pobject && item.objectid == this.$refs.lisYtable.getCurrentRow().id && item.powercode == s_item.powercode && item.flag == "add") {
                        XE.remove(this.tab_lis_savedata, key);
                        isAdd = true;
                    }
                });
                if (!isAdd) {
                    //没有添加记录 新增一条删除记录
                    let insert = {
                        groupno: this.main_secsysrole_info.roleno,
                        powerobject: this.tab_lis_pobject,
                        objectid: this.$refs.lisYtable.getCurrentRow().id,
                        powercode: s_item.powercode,
                        flag: "del",
                    };
                    this.tab_lis_savedata.push(insert);
                }
            });

            //处理已有/未有表
            this.tab_lis_nohavendata.push(this.tab_lis_havendata[rowIndex]);
            this.tab_lis_havendata.splice(rowIndex, 1);
            if (this.rowIndex > 0) {
                this.$refs.lisYtable.setCurrentRow(this.tab_lis_havendata[rowIndex - 1]);
                this.tab_lis_getpower(this.tab_lis_havendata[rowIndex - 1]);
            } else {
                this.tab_lis_pdictdata = [];
            }
            let that = this;
            XE.delay(
                function (name) {
                    that.$refs.lisYtable.scrollToRow(that.tab_lis_havendata[rowIndex - 1]);
                },
                200,
                "settimeout500"
            );
        },
        tab_lis_dbclickAddEvent({ row, rowIndex, column, columnIndex }, event) {
            if (this.isarea && this.main_secsysrole_info.hospcode == "All" && this.$tool.getSession(this.$tool.loginutype) != "G" && this.$tool.getSession(this.$tool.loginutype) != "R") {
                this.$message({
                    type: "warning",
                    message: "医院代码All不可修改！",
                });
                return false;
            }
            this.tab_lis_havendata.push(this.tab_lis_nohavendata[rowIndex]);
            this.tab_lis_nohavendata.splice(rowIndex, 1);
            this.$refs.lisYtable.setCurrentRow(this.tab_lis_havendata[this.tab_lis_havendata.length - 1]);
            let that = this;
            XE.delay(
                function (name) {
                    that.$refs.lisYtable.scrollToRow(that.tab_lis_havendata[that.tab_lis_havendata.length - 1]);
                },
                200,
                "settimeout200"
            );
            this.$nextTick(() => {
                //自动记忆上一次
                if (this.tab_lis_ismemory) {
                    if (this.tab_lis_pdictdata.length <= 0) {
                        this.tab_lis_pdictdata = [];
                        this.tab_lis_pdictdata = XE.clone(this.tab_lis_pdictdata_old, true);
                    } else {
                        //自动记忆时 要默认把已选中的数据 添加到保存数据结构里面去
                        let selectRecords = this.$refs.lisDicttable.getSelectRecords();
                        XE.each(selectRecords, (item, key) => {
                            let insert = {
                                groupno: this.main_secsysrole_info.roleno,
                                powerobject: this.tab_lis_pobject,
                                objectid: this.$refs.lisYtable.getCurrentRow().id,
                                powercode: item.powercode,
                                flag: "add",
                            };
                            this.tab_lis_savedata.push(insert);
                        });
                    }
                }
                //否则 全空
                else {
                    this.tab_lis_pdictdata = [];
                    this.tab_lis_pdictdata = XE.clone(this.tab_lis_pdictdata_old, true);
                }
            });
        },
        tab_lis_selectChanegCEvent(checked) {
            //先保存已经选中的数据
            let selectRecords = this.$refs.lisDicttable.getSelectRecords();
            //console.log("selectRecords", selectRecords);
            if (checked) {
                XE.each(this.tab_lis_pdictdata_old, (itemall, keyall) => {
                    //全选  找没有选中的数据处理
                    let ishave = false;
                    XE.each(selectRecords, (itemhave, keyhave) => {
                        if (itemall.powercode == itemhave.powercode) {
                            ishave = true;
                        }
                    });
                    if (!ishave) {
                        // console.log("1");
                        //筛选出没有选中的数据
                        let isDel = false;
                        XE.each(this.tab_lis_savedata, (item, key) => {
                            if (item.groupno == this.main_secsysrole_info.roleno && item.powerobject == this.tab_lis_pobject && item.objectid == this.$refs.lisYtable.getCurrentRow().id && item.powercode == itemall.powercode && item.flag == "del") {
                                XE.remove(this.tab_lis_savedata, key);
                                isDel = true;
                            }
                        });
                        if (!isDel) {
                            //没有删除 新增一条添加记录
                            let insert = {
                                groupno: this.main_secsysrole_info.roleno,
                                powerobject: this.tab_lis_pobject,
                                objectid: this.$refs.lisYtable.getCurrentRow().id,
                                powercode: itemall.powercode,
                                flag: "add",
                            };
                            this.tab_lis_savedata.push(insert);
                        }
                    }
                });
                this.$refs.lisDicttable.setAllSelection(true);
            } else {
                XE.each(this.tab_lis_pdictdata_old, (itemall, keyall) => {
                    //全选  找选中的数据处理
                    let ishave = false;
                    XE.each(selectRecords, (itemhave, keyhave) => {
                        if (itemall.powercode == itemhave.powercode) {
                            ishave = true;
                        }
                    });
                    if (ishave) {
                        //找有没有添加记录  如果有：直接删除该添加记录  如果没有：新增一条删除记录
                        let isAdd = false;
                        XE.each(this.tab_lis_savedata, (item, key) => {
                            if (item.groupno == this.main_secsysrole_info.roleno && item.powerobject == this.tab_lis_pobject && item.objectid == this.$refs.lisYtable.getCurrentRow().id && item.powercode == itemall.powercode && item.flag == "add") {
                                XE.remove(this.tab_lis_savedata, key);
                                isAdd = true;
                            }
                        });
                        if (!isAdd) {
                            //没有添加记录 新增一条删除记录
                            let insert = {
                                groupno: this.main_secsysrole_info.roleno,
                                powerobject: this.tab_lis_pobject,
                                objectid: this.$refs.lisYtable.getCurrentRow().id,
                                powercode: itemall.powercode,
                                flag: "del",
                            };
                            this.tab_lis_savedata.push(insert);
                        }
                    }
                });
                this.$refs.lisDicttable.setAllSelection(false);
            }
            // console.log(this.tab_lis_savedata);
        },
        tab_lis_dictTablechangeEvent({ selection, reserves, checked, row, rowIndex, $rowIndex, column, columnIndex, $columnIndex, cell }, event) {
            if (checked) {
                //找有没有删除记录  如果有：直接删除该删除记录，如果没有：新增一条添加记录
                let isDel = false;
                XE.each(this.tab_lis_savedata, (item, key) => {
                    if (item.groupno == this.main_secsysrole_info.roleno && item.powerobject == this.tab_lis_pobject && item.objectid == this.$refs.lisYtable.getCurrentRow().id && item.powercode == row.powercode && item.flag == "del") {
                        XE.remove(this.tab_lis_savedata, key);
                        isDel = true;
                    }
                });
                if (!isDel) {
                    //没有删除 新增一条添加记录
                    let insert = {
                        groupno: this.main_secsysrole_info.roleno,
                        powerobject: this.tab_lis_pobject,
                        objectid: this.$refs.lisYtable.getCurrentRow().id,
                        powercode: row.powercode,
                        flag: "add",
                    };
                    this.tab_lis_savedata.push(insert);
                }
            } else {
                //找有没有添加记录  如果有：直接删除该添加记录  如果没有：新增一条删除记录
                let isAdd = false;
                XE.each(this.tab_lis_savedata, (item, key) => {
                    if (item.groupno == this.main_secsysrole_info.roleno && item.powerobject == this.tab_lis_pobject && item.objectid == this.$refs.lisYtable.getCurrentRow().id && item.powercode == row.powercode && item.flag == "add") {
                        XE.remove(this.tab_lis_savedata, key);
                        isAdd = true;
                    }
                });
                if (!isAdd) {
                    //没有添加记录 新增一条删除记录
                    let insert = {
                        groupno: this.main_secsysrole_info.roleno,
                        powerobject: this.tab_lis_pobject,
                        objectid: this.$refs.lisYtable.getCurrentRow().id,
                        powercode: row.powercode,
                        flag: "del",
                    };
                    this.tab_lis_savedata.push(insert);
                }
            }
        },
        tab_lis_saveBtnEvent() {
            if (this.isarea && this.main_secsysrole_info.hospcode == "All" && this.$tool.getSession(this.$tool.loginutype) != "G" && this.$tool.getSession(this.$tool.loginutype) != "R") {
                this.$message({
                    type: "warning",
                    message: "医院代码All不可修改！",
                });
                return false;
            }
            if(this.tab_lis_savedata.length<=0){
                alert(this.tab_lis_savedata.length)
                this.$message({
                    type: "warning",
                    message: "请选择权限！",
                });
                return false;
            }
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "lis_save",
                        data: this.tab_lis_savedata,
                    },
                })
                .then((res) => {
                    if (res == "1") {
                        this.tab_lis_savedata = []; //保存成功要清空上次变动数据
                        this.$message({
                            message: "保存成功！",
                            type: "success",
                        });
                    } else {
                        this.$message.error(res);
                    }
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        lisYtable_changeEvent({ row, rowIndex, column, columnIndex }, event) {
            this.tab_lis_getpower(row);
        },
        tab_lis_getpower(row) {
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "lis_getpower",
                        roleno: this.main_secsysrole_info.roleno,
                        powerobject: this.tab_lis_pobject,
                        objectid: row.id,
                    },
                })
                .then((res) => {
                    this.tab_lis_pdictdata = [];
                    this.tab_lis_pdictdata = XE.clone(this.tab_lis_pdictdata_old, true);
                    let checks = [];
                    XE.each(this.tab_lis_pdictdata, (dictitem, dictkey) => {
                        //选中已经保存的
                        XE.each(res, (resitem, reskey) => {
                            if (dictitem.powercode == resitem.powercode) {
                                checks.push(dictitem);
                            }
                        });
                        //选中待保存的
                        XE.each(this.tab_lis_savedata, (saveitem, savekey) => {
                            if (dictitem.powercode == saveitem.powercode && row.id == saveitem.objectid) {
                                checks.push(dictitem);
                            }
                        });
                    });
                    this.$refs.lisDicttable.setSelection(checks, true);
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        tab_lis_getalldata() {
            this.tab_lis_savedata = []; //刷新界面要清空上次变动数据
            if (this.main_secsysrole_info.roleno == "") {
                this.$message.error("请选择角色数据！");
                this.tab_lis_pdictdata = [];
                this.tab_lis_havendata = [];
                this.tab_lis_nohavendata = [];
                return false;
            }
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "lis_getalldata",
                        roleno: this.main_secsysrole_info.roleno,
                        tab_lis_pobject: this.tab_lis_pobject,
                    },
                })
                .then((res) => {
                    if (res != "-2") {
                        this.tab_lis_havendata = res[0].Data;
                        this.tab_lis_nohavendata = res[1].Data;
                        //this.tab_lis_pdictdata = XE.clone(res[2].Data, true);
                        this.tab_lis_pdictdata_old = XE.clone(res[2].Data, true);
                        if (this.tab_lis_havendata.length > 0) {
                            this.$refs.lisYtable.setCurrentRow(this.tab_lis_havendata[0]);
                            this.tab_lis_getpower(this.tab_lis_havendata[0]);
                        } else {
                            this.tab_lis_pdictdata = [];
                        }
                    } else {
                        this.$message({
                            type: "warning",
                            message: "角色数据错误！",
                        });
                    }
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        lis_rowspanmethod({ row, $rowIndex, column, data }) {
            let fields = ["powerobjectname", "powerclassname"];
            let cellValue = row[column.property];
            if (cellValue && fields.includes(column.property)) {
                let prevRow = data[$rowIndex - 1];
                let nextRow = data[$rowIndex + 1];
                if (prevRow && prevRow[column.property] === cellValue) {
                    return { rowspan: 0, colspan: 0 };
                } else {
                    let countRowspan = 1;
                    while (nextRow && nextRow[column.property] === cellValue) {
                        nextRow = data[++countRowspan + $rowIndex];
                    }
                    if (countRowspan > 1) {
                        return { rowspan: countRowspan, colspan: 1 };
                    }
                }
            }
        },
        tab_cdsq_getdata() {
            if (this.main_secsysrole_info.roleno == "") {
                this.$message.error("请选择角色数据！");
                return false;
            }
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysprg_gettree",
                        roleno: this.main_secsysrole_info.roleno,
                    },
                })
                .then((res) => {
                    this.tab_cdsq_data = res[0];
                    this.tab_cdsq_tree_havendata = res[1];
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        //菜单授权保存
        tab_cdsq_saveTreeEvent() {
            let usedidlist = this.getCheckTreeMenu();
            this.menuTreeSave(this.main_secsysrole_info.roleno, usedidlist);
        },
        //菜单授权复制保存
        //菜单授权复制与粘贴
        menuauthevent(flag) {
            if (flag == "copy") {
                this.menuauth.orirolenname = XE.clone(this.main_secsysrole_info.rolename, true);
                this.menuauth.orirolenno = XE.clone(this.main_secsysrole_info.roleno, true);
                this.copydata = this.getCheckTreeMenu();
            } else {
                if (!this.copydata) {
                    this.$alert("来源角色菜单授权权限为空！", "提示");
                    return false;
                }
                let msg = "确定将角色:[" + this.menuauth.orirolenname + "]的菜单授权复制到角色:[" + this.main_secsysrole_info.rolename + "]吗？";
                this.$confirm(msg, "提示")
                    .then(() => {
                        this.menuTreeSave(this.main_secsysrole_info.roleno, this.copydata);
                    })
                    .catch(() => {});
            }
        },
        //获取勾选的菜单
        getCheckTreeMenu() {
            var idlist = this.$refs.tab_cdsq_tree.getCheckedKeys();
            var usedidlist = [];
            for (let i = 0; i < idlist.length; i++) {
                if (!XE.isNull(idlist[i])) {
                    if (idlist[i].split("$").length == 2) {
                        usedidlist.push(idlist[i]);
                    }
                }
            }
            return usedidlist;
        },
        //保存
        menuTreeSave(roleno, usedidlist) {
            if (this.isarea && this.main_secsysrole_info.hospcode == "All" && this.$tool.getSession(this.$tool.loginutype) != "G" && this.$tool.getSession(this.$tool.loginutype) != "R") {
                this.$pub.message(this, "warning", "医院代码All不可修改！");
                return false;
            }
            if(usedidlist.length<=0){
                this.$pub.message(this, "warning", "请勾选菜单！");
                return false;
            }

            let _this = this;
            //let datajson = JSON.stringify(usedidlist);
            _this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secrolefunc_save",
                        roleno: roleno,
                        data: usedidlist,
                    },
                })
                .then((res) => {
                    if (res == "1") {
                        _this.$pub.message(_this, "保存成功！", "success");
                        _this.tab_cdsq_getdata();
                    } else {
                        _this.$message.error(res);
                    }
                })
                .catch((e) => {
                    _this.$message.error(e);
                });
        },
        filterNode(value, data) {
            if (!value) return true;
            return data.label.indexOf(value) !== -1;
        },
        tab_lis_checkMethod({ row }) {
            if (this.main_secsysrole_info.hospcode == "All") {
                return false;
            } else {
                return true;
            }
        },
        //"rm-cancel"; //作废
        //"rm-disable"; //禁用
        //"rm-readonly"; //只读
        //"rm-alert"; //警告
        LisDictRowClassName({ row, rowIndex }) {
            let isCheck = false;
            let selectRecords = this.$refs.lisDicttable.getSelectRecords();
            XE.each(selectRecords, (item, key) => {
                if (item.powercode == row.powercode) {
                    isCheck = true;
                }
            });
            if (!isCheck) {
                return "rm-readonly";
            }
        },
        //add报告项目按类别取消授权
        tab_bgxmalb_dbclickDelEvent({ row, column }) {
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsysbgxmalb_dbclick_del",
                        roleno: _this.main_secsysrole_info.roleno,
                        itemclassid: row.itemclassid,
                        itemclasscode: row.itemclasscode,
                        havechild: row.havechild,
                    },
                })
                .then((res) => {
                    if (res.errcode == "1") {
                        _this.$pub.message(_this, "删除成功！", "success");
                        _this.tab_bgxmalb_havedata();
                        _this.tab_bgxmalb_nohavedata();
                    } else {
                        _this.$alert(res.errmsg, "提示");
                    }
                })
                .catch((e) => {
                    this.$alert(e, "提示");
                });
        },
        //add报告项目按类别授权
        tab_bgxmalb_dbclickAddEvent({ row, column }) {
            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG111",
                    method: "post",
                    data: {
                        action: "secsybgxmalb_dbclick_add",
                        roleno: _this.main_secsysrole_info.roleno,
                        itemclassid: row.itemclassid,
                        itemclasscode: row.itemclasscode,
                        havechild: row.havechild,
                    },
                })
                .then((res) => {
                    if (res.errcode == "1") {
                        _this.$pub.message(_this, "添加成功！", "success");
                        _this.tab_bgxmalb_havedata();
                        _this.tab_bgxmalb_nohavedata();
                    } else {
                        _this.$alert(res.errmsg, "提示");
                    }
                })
                .catch((e) => {
                    this.$alert(e, "提示");
                });
        },
    },
};
</script>

<style scoped>
.pagetop {
    width: 100%;
    height: 35px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenter {
    position: absolute;
    top: 40px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    background-color: blueviolet;
    position: absolute;
    height: 100%;
    left: 0px;
    right: 855px;
    overflow: auto;
}

.middle-right {
    background-color: chartreuse;
    position: absolute;
    height: 100%;
    width: 850px;
    right: 0px;
}

::v-deep .vxe-body--row.row-stop {
    color: white !important;
    background-color: rgb(255, 192, 192) !important;
}
::v-deep .vxe-body--row.row-new {
    color: red !important;
}
::v-deep .vxe-body--row.row-green {
    background-color: #187 !important;
    color: #fff;
}
::v-deep .vxe-body--column.col-red {
    background-color: red;
    color: #fff;
}
::v-deep .el-input.is-disabled .el-input__inner {
    color: black;
}
::v-deep .el-checkbox.is-disabled .el-checkbox__label {
    color: black;
}
::v-deep .el-textarea.is-disabled .el-textarea__inner {
    color: black;
}
::v-deep .el-checkbox__inner::after {
    border: 2px solid #000000 !important;
    box-sizing: content-box;
    content: "";
    border-left: 0 !important;
    border-top: 0 !important;
    height: 7px;
    left: 4px;
    position: absolute;
    top: 1px;
    transform: rotate(45deg) scaleY(0);
    width: 3px;
    transition: transform 0.15s ease-in 0.05s;
    transform-origin: center;
}
::v-deep .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #000000;
    cursor: not-allowed;
}
::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
    background-color: #ffffff !important;
}
.middle-tab-bottom {
    position: absolute;
    top: 37px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
table tr td:nth-child(odd) {
    text-align: right;
    white-space: nowrap;
}
table tr td:nth-child(even) {
    text-align: left;
}
table tr td:nth-child(1) {
    width: 80px;
}
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}
::v-deep tr.vxe-body--row.row--current {
    color: #000000;
    font-weight: bold;
}
::v-deep .dialogselect .el-input__inner {
    width: 80px
}

</style>